<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;
use Illuminate\Database\Eloquent\SoftDeletes;

class ProductReply extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     * 表中的类型状态
     */
    //参与的活动类型
    public $replyTypeTypeEnum = [
        'noActivity' => '普通商品',
        'seckill' => '秒杀',
        'bargain' => '砍价',
        'combination' => '拼团'
    ];

    /**
     * 强制转换类型
     */
    protected $casts = [
        'pics' => 'array',
        'merchant_reply_time' => 'date'
    ];

    /**
     * 可搜索字段
     */
    public $searchable = [
        'user_id',
        'order_id',
        'product_id',
        'is_reply',
        'nickname',
        'product_name',
    ];

    /**
     * 可模糊搜索字段
     */
    public $searchableModels = [
        'nickname' => '%field%',
        'product_name' => '%field%'
    ];

    /**
     * 可批量赋值字段
     */
    public $fillable = [
        'product_score',
        'service_score',
        'comment',
        'pics',
        'merchant_reply_content',
        'merchant_reply_time',
        'is_reply',
        'user_id',
        'order_id',
        'unique',
        'product_id',
        'nickname',
        'avatar',
        'reply_type',
    ];

    /**
     * 可排序字段
     */
    public $sortable = ['created_at', 'id'];

    /**
     * 默认排序字段
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 关联的用户
     */
    function user(){
        return $this->belongsTo(User::class,'user_id','id');
    }

    /**
     * 关联的订单
     */
    function order(){
        return $this->belongsTo(Order::class,'order_id','id');
    }

    /**
     * 关联的商品
     */
    function product(){
        return $this->belongsTo(Product::class,'product_id','id');
    }


}
